package com.xuecheng.content.controller;

import com.xuecheng.api.content.model.TeachplanApi;
import com.xuecheng.api.content.model.dto.TeachplanDTO;
import com.xuecheng.api.content.model.vo.TeachplanVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.TeachplanConvert;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程计划 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
@RequestMapping("teachplan")
public class TeachplanController implements TeachplanApi {

    @Autowired
    private TeachplanService teachplanService;


    @GetMapping("teachplan/{courseId}/tree-nodes")
    public TeachplanDTO getTreeNodes(@PathVariable Long courseId) {

        Long companyId = SecurityUtil.getCompanyId();

        TeachplanDTO dto = teachplanService.getTreeNodes(courseId, companyId);

        return dto;
    }

    @PostMapping("teachplan")
    public TeachplanDTO createOrModifyTeachplan(@RequestBody TeachplanVO vo) {

        Long companyId = SecurityUtil.getCompanyId();

        TeachplanDTO dto = TeachplanConvert.INSTANCE.vo2dto(vo);

        TeachplanDTO resultDTO = teachplanService.createOrModifyTeachplan(dto, companyId);

        return resultDTO;
    }


}
